import java.io.InputStream;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2022-10-13
 * Time: 下午 14:15
 */
public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        while (scan.hasNext()) {
            String str = scan.nextLine();
            int num = Integer.MAX_VALUE;
            int n = 0;

            while (num >= 10) {
                num = 0;
                n = 0;


                while (n < str.length()) {
                    char ch = str.charAt(n);
                    num += ch - '0';
                    n++;
                }

                if(num >= 10) {
                    str = String.valueOf(num);
                }
            }
            System.out.println(num);
        }
    }
}

